Repository navigation
qwen4_exp: default the n-gram hash seed to 1234, and check the constants at load (rebased #1) - #2
Merged
Conversation
…nts at load Re-applied onto da1148f by @sje397: eauchs#1 no longer applies because da1148f reorganised the n-gram shard handling underneath it. The change is Beata's; only the anchors moved. The seed is not in config.json, so the default is load-bearing: a different seed rebuilds different multipliers and every PLE lookup lands on the wrong rows. `Model.sanitize` now compares the constants rebuilt from the config against the checkpoint's own copies and raises on mismatch, so a wrong seed fails loudly instead of silently reading the wrong rows. Verified against a real checkpoint, which the test alone cannot do (it constructs the model, so any self-consistent seed satisfies it): the community oQ4e conversion of this architecture at Jundot/Qwen3.8-Flash-Next-oQ4e-mtp carries layer_multipliers (3,), ngram_heads_vocab_sizes (16,) and ngram_heads_offsets (16,), and all three match the seed-1234 rebuild exactly at ple_layer_index 0. Candidates 0, 617 and 1235 do not match any layer index. So 1234 is not merely plausible -- it is the seed written into a shipped checkpoint, which is why the guard is worth having at load rather than trusting the default.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #1 by @beatakouchnir — the same change, re-applied onto
da1148f9. #1 ismergeable_state: dirtybecauseda1148f9reorganised the n-gram shard handling underneath it (_NGRAM_SHARD_RE, both key layouts); nothing in the change was wrong, only its anchors moved. Authorship is preserved on the commit.Why a guard and not just a default.
seedis absent fromconfig.json, so the default is load-bearing: a different seed rebuilds different multipliers and every PLE lookup silently lands on the wrong rows.sanitizenow compares the constants rebuilt from the config against the checkpoint's own copies and raises on mismatch, instead of degrading in silence.Verified against a real checkpoint, because the test cannot.
test_qwen4_exp_ngram_constants_are_checkedbuilds the model and compares it to itself, so any self-consistent seed satisfies it — it can pin that a mismatch is rejected, but not that 1234 is the reference's seed. A shipped artifact can:That checkpoint is a community oQ4e conversion of this architecture; the constants are small tensors and can be read from a shard header without downloading the weights. So
1234is not merely plausible — it is the seed written into a shipped artifact, which is the argument for checking it at load rather than trusting the default.Falsified rather than merely green. Deleting the
_check_ngram_constantcall fails exactly the new test; setting the default back to0also fails it (theassertFalseon a seed-0 model's constants). Both files restored byte-identical afterwards (sha256 checked).One thing worth knowing before review, unrelated to this patch:
tests/test_models.py::test_qwen4_expis red atda1148f9— the prefill-vs-stepwise consistency assertion. It is not caused by this change: it fails identically with and without it, onda1148f9,2196836andac83bb4, and it is green at365170c(the commit that added the model). Measured:max|prefill - stepwise| = 1.07e-3against a magnitude of1.20(~0.09%), so it exceedsatol=1e-4while still agreeing at1e-2. That reads as a tolerance that has drifted rather than a wrong result, but the suite is red at head, so it is worth deciding deliberately whether to relax the tolerance or chase the precision loss.Test status here:
test_qwen4_exp_ngram_constants_are_checked— PASStest_qwen4_exp— FAIL (pre-existing, unchanged by this patch)